package mysql.Base;

import java.sql.*;

public class mysqltestdemo {
    public static void main(String[] args) throws Exception {
//     JDBC的使用
//        1.通过反射加在 加载驱动
        Class.forName("com.mysql.jdbc.Driver");
//        2.建立连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://master:3306/shujia",
                "root", "123456");
//        3.创建执行器,用来执行SQL语句
//          1.createStatement()
//          2.prepareStatement()
        Statement statement = connection.createStatement();
        String sql ="select * from student";
//        4.执行SQL语句
        ResultSet rs = statement.executeQuery(sql);
//        5.获取结果
        while(rs.next()){
            System.out.println(rs.getInt("id"));
            System.out.println(rs.getString("name"));
            System.out.println(rs.getInt("sex"));
            System.out.println(rs.getString("age"));
        }
//        6.关闭
        rs.close();
        statement.close();
        connection.close();
    }
}
